package com.aiyige.page.pay.model;

import android.os.Parcel;
import android.os.Parcelable;

import com.aiyige.model.eshop.Order;

/**
 * Created by zhuyakun on 2018/4/23.
 */
public class PayResult implements Parcelable {
    public static final int RESULT_CODE_OK = 1;
    public static final int RESULT_CODE_FAILED = 2;
    public static final int RESULT_CODE_CANCELED = 3;

    int payMethod;
    int resultCode;
    String message;

    public PayResult() {
    }

    private PayResult(Builder builder) {
        setPayMethod(builder.payMethod);
        setResultCode(builder.resultCode);
        setMessage(builder.message);
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public int getPayMethod() {
        return payMethod;
    }

    public void setPayMethod(int payMethod) {
        this.payMethod = payMethod;
    }

    public int getResultCode() {
        return resultCode;
    }

    public void setResultCode(int resultCode) {
        this.resultCode = resultCode;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public static final class Builder {
        private int payMethod;
        private int resultCode;
        private String message;

        private Builder() {
            payMethod = Order.PAY_METHOD_WECHATPAY_APP;
            resultCode = RESULT_CODE_CANCELED;
            message = "";
        }

        public Builder payMethod(int payMethod) {
            this.payMethod = payMethod;
            return this;
        }

        public Builder resultCode(int resultCode) {
            this.resultCode = resultCode;
            return this;
        }

        public Builder message(String message) {
            this.message = message;
            return this;
        }

        public PayResult build() {
            return new PayResult(this);
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.payMethod);
        dest.writeInt(this.resultCode);
        dest.writeString(this.message);
    }

    protected PayResult(Parcel in) {
        this.payMethod = in.readInt();
        this.resultCode = in.readInt();
        this.message = in.readString();
    }

    public static final Parcelable.Creator<PayResult> CREATOR = new Parcelable.Creator<PayResult>() {
        @Override
        public PayResult createFromParcel(Parcel source) {
            return new PayResult(source);
        }

        @Override
        public PayResult[] newArray(int size) {
            return new PayResult[size];
        }
    };
}
